<template>
	<view>
		<view class="cu-custom" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',bgColor]">
				<view class="action" @tap="BackPage" v-if="isBack">
					<text class="cuIcon-back"></text>
					<slot name="backText"></slot>
				</view>
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<slot name="content"></slot>
				</view>
				<slot name="right"></slot>
			</view>
		</view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				StatusBar: "0",
				CustomBar: "50"
			};
		},
		name: 'cu-custom',
		computed: {
			style() {
				var StatusBar= this.StatusBar;
				var CustomBar= this.CustomBar;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},

		created() {
			const appData = getApp().globalData
			// #ifdef APP-PLUS || MP-WEIXIN || MP-ALIPAY
				this.StatusBar = appData.StatusBar
				this.CustomBar = appData.CustomBar
				console.log(appData,"999389479823498")
			// #endif
		},
		props: {
			bgColor: {//背景颜色，类名
				type: String,
				default: ''
			},
			isBack: {//是否存在返回按钮
				type: [Boolean, String],
				default: false
			},
			bgImage: {//背景图片
				type: String,
				default: ''
			},
		},
		methods: {
			BackPage() {
				if (getCurrentPages().length < 2 && 'undefined' !== typeof __wxConfig) {
					let url = '/' + __wxConfig.pages[0]
					return uni.redirectTo({url})
				}
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style>

</style>
